package com.naicheng.ivote.uiself;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;


public class ToastUtils {

	private static Context mContext = null;
	private static Toast mToast = null;
	private static Toast centerToast = null;
	private static Toast centerDownToast = null;
	private static Toast diyToast = null;

	/**
	 * 普通的toast
	 * 
	 * @param context
	 * @param content
	 */
	public static void getNormalToast(Context context, String content) {

		if (ToastUtils.mContext == context) {
			// mToast.cancel();
			if (null == mToast) {
				mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			}
			mToast.setText(content);
		} else {
			ToastUtils.mContext = context;
			mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
		}
		mToast.show();
	}

	/**
	 * 居中的普通的toast
	 * 
	 * @param context
	 * @param content
	 */
	public static void getNormalCenterToast(Context context, String content) {
		if (ToastUtils.mContext == context) {
			if (null == centerToast) {
				centerToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			}
			centerToast.setText(content);
		} else {
			ToastUtils.mContext = context;
			centerToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			centerToast.setGravity(Gravity.CENTER, 0, 0);
		}
		centerToast.show();
	}

	/**
	 * 中心稍微偏下的toast
	 * 
	 * @param context
	 * @param content
	 */
	public static void getCenterDownToast(Context context, String content) {
		if (ToastUtils.mContext == context) {
			if (null == centerDownToast) {
				centerDownToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			}
			centerDownToast.setText(content);
		} else {
			ToastUtils.mContext = context;
			centerDownToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			centerDownToast.setGravity(Gravity.CENTER, 0, 150);
		}
		centerDownToast.show();
	}
	
	/**
	 * 自定义位置的toast
	 * 
	 * @param context
	 * @param position
	 * @param content
	 */
	public static void getDiyToast(Context context, int x, int y, String content) {
		if (ToastUtils.mContext == context) {
			if (null == diyToast) {
				diyToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			}
			diyToast.setText(content);
		} else {
			ToastUtils.mContext = context;
			diyToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			diyToast.setGravity(Gravity.CENTER, x, y);
		}
		diyToast.show();
	}
	
	public static void getDiyToast(Context context, int position, String content) {
		if (ToastUtils.mContext == context) {
			if (null == diyToast) {
				diyToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			}
			diyToast.setText(content);
		} else {
			ToastUtils.mContext = context;
			diyToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
			diyToast.setGravity(Gravity.CENTER, 0, position);
		}
		diyToast.show();
	}

}
